package openrouter

type ChatCompletionMessage struct {
	Role    MessageRole `json:"role"`
	Content string      `json:"content"`
}

type ChatCompletionRequest struct {
	Model       string                  `json:"model"`
	Messages    []ChatCompletionMessage `json:"messages"`
	Stream      bool                    `json:"stream"`      // 是否流式输出
	Temperature float64                 `json:"temperature"` // 温度（0 - 2）
	TopP        float64                 `json:"top_p"`       // 采样温度（0 - 1）
	TokK        float64                 `json:"tok_k"`       // 采样顶部（0 - 100）
}

type ChatCompletionResponse struct {
	Id       string `json:"id"`
	Provider string `json:"provider"`
	Model    string `json:"model"`
	Object   string `json:"object"`
	Created  int    `json:"created"`
	Choices  []struct {
		Logprobs interface{} `json:"logprobs"`
		Index    int         `json:"index"`
		Message  struct {
			Role      string      `json:"role"`
			Content   string      `json:"content"`
			Refusal   interface{} `json:"refusal"`
			Reasoning interface{} `json:"reasoning"`
		} `json:"message"`
	} `json:"choices"`
	Usage struct {
		PromptTokens     int `json:"prompt_tokens"`
		CompletionTokens int `json:"completion_tokens"`
		TotalTokens      int `json:"total_tokens"`
	} `json:"usage"`
}

type CreateChatCompletionStreamOption struct {
	OnMessage func(sse ChatCompletionSSEResponse)
	OnEnd     func()
}

type ChatCompletionSSEResponse struct {
	Id       string `json:"id"`
	Provider string `json:"provider"`
	Model    string `json:"model"`
	Object   string `json:"object"`
	Created  int    `json:"created"`
	Choices  []struct {
		Index int `json:"index"`
		Delta struct {
			Role    string `json:"role"`
			Content string `json:"content"`
		} `json:"delta"`
		FinishReason       interface{} `json:"finish_reason"`
		NativeFinishReason interface{} `json:"native_finish_reason"`
	} `json:"choices"`
}

type GenerationResponse struct {
	Data struct {
		Id                     string  `json:"id"`
		TotalCost              float64 `json:"total_cost"`
		CreatedAt              string  `json:"created_at"`
		Model                  string  `json:"model"`
		Origin                 string  `json:"origin"`
		Usage                  float64 `json:"usage"`
		IsByok                 bool    `json:"is_byok"`
		UpstreamId             string  `json:"upstream_id"`
		CacheDiscount          float64 `json:"cache_discount"`
		AppId                  int     `json:"app_id"`
		Streamed               bool    `json:"streamed"`
		Cancelled              bool    `json:"cancelled"`
		ProviderName           string  `json:"provider_name"`
		Latency                int     `json:"latency"`
		ModerationLatency      int     `json:"moderation_latency"`
		GenerationTime         int     `json:"generation_time"`
		FinishReason           string  `json:"finish_reason"`
		NativeFinishReason     string  `json:"native_finish_reason"`
		TokensPrompt           int     `json:"tokens_prompt"`
		TokensCompletion       int     `json:"tokens_completion"`
		NativeTokensPrompt     int     `json:"native_tokens_prompt"`
		NativeTokensCompletion int     `json:"native_tokens_completion"`
		NativeTokensReasoning  int     `json:"native_tokens_reasoning"`
		NumMediaPrompt         int     `json:"num_media_prompt"`
		NumMediaCompletion     int     `json:"num_media_completion"`
		NumSearchResults       int     `json:"num_search_results"`
	} `json:"data"`
}

type GetCreditsResponse struct {
	Data struct {
		TotalCredits float64 `json:"total_credits"`
		TotalUsage   float64 `json:"total_usage"`
	} `json:"data"`
}

type GetModelsResponse struct {
	Data []struct {
		Id          string `json:"id"`
		Name        string `json:"name"`
		Description string `json:"description"`
		Pricing     struct {
			Prompt     string `json:"prompt"`
			Completion string `json:"completion"`
		} `json:"pricing"`
	} `json:"data"`
}
